package com.aaa.gs;

import com.aaa.gs.config.MyRule;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@MapperScan("com.aaa.gs.mapper")
//@EnableEurekaClient //开启eureka 客户端  该注释只对注册中心eureka 有效
@EnableDiscoveryClient //开启发现客户端，该注释可以是任意注册中心
@EnableTransactionManagement //开启事务管理
@RibbonClient(name = "goodsClient",configuration = MyRule.class)
public class GoodsApp {
    public static void main(String[] args) {
        SpringApplication.run(GoodsApp.class,args);
    }

    /**
     * 初始化RestTemplate对象
     * @return
     */
    @Bean // <beans id='restTemplate' class='org.springframework.web.client.RestTemplate'></beans>
    @LoadBalanced //调用远程接口时，要使用配置的负载均衡规则
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }
}
